//
//  DeviceInfoDataModel.swift
//  TimeBoat
//
//  Created by Jun on 2022/9/8.
//  Copyright © 2022 Time Boat. All rights reserved.
//

import Foundation

/// 设备信息
@objcMembers class DeviceInfoDataModel: NSObject {
    /// 标示符 2Byte
    var indication: UInt16 = 0
    /// 计步 1Byte
    var stepCount: UInt8 = 0
    /// 心率 1Byte
    var heartRate: UInt8 = 0
    /// 睡眠 1Byte
    var sleep: UInt8 = 0;
    /// 跑步 1Byte
    var run: UInt8 = 0
    ///  徒步 1Byte
    var hiking: UInt8 = 0
    /// 马拉松 1Byte
    var marathon: UInt8 = 0
    /// 跳绳 1Byte
    var skippingRope: UInt8 = 0
    /// 户外游泳 1Byte
    var swim: UInt8 = 0
    /// 攀岩 1Byte
    var rockClimbing: UInt8 = 0
    /// 滑雪 1Byte
    var skiing: UInt8 = 0
    ///  骑行 1Byte
    var ride: UInt8 = 0
    /// 划船 1Byte
    var boat: UInt8 = 0
    ///  蹦极 1byte
    var bungeeJumping: UInt8 = 0
    ///  登山 1Byte
    var mountaineering: UInt8 = 0
    ///  跳伞 1Byte
    var parachuteJump: UInt8 = 0
    ///  20 高尔夫 1Byte
    var golf: UInt8 = 0
    ///  冲浪 1Byte
    var surfing: UInt8 = 0
    ///  跑步机 1Byte
    var runningMachine: UInt8 = 0
    ///  主动心率测量开关 1Byte 1：测量打开，0：测量关闭 （默认）
    var measureHeartRate: UInt8 = 0
    ///  蓝牙地址 6Byte
    var bleAddress: [UInt8]? = nil
    /// 羽毛球 1Byte
    var badminton: UInt8 = 0
    /// 篮球 1Byte
    var basketball: UInt8 = 0
    ///  足球 1Byte
    var footBall: UInt8 = 0
    ///  血氧 1Byte
    var bloodOxygen: UInt8 = 0
    
    convenience init(buf: [UInt8]) {
        self.init()
        
        var index: Int = 0

        if (index + 2 <= buf.count) {
            //  标示符 2Byte
            indication = UInt16.toUInt16(buf: buf, offset: index)
            index += 2
        }

        if (index + 1 <= buf.count) {
            // 计步 1Byte
            stepCount = buf[index]
            index += 1
        }

        if (index + 1 <= buf.count) {
            // 心率 1Byte
            heartRate = buf[index]
            index += 1
        }

        if (index + 1 <= buf.count) {
            // 睡眠 1Byte
            sleep = buf[index]
            index += 1
        }

        if (index + 1 <= buf.count) {
            // 跑步 1Byte
            run = buf[index]
            index += 1
        }

        if (index + 1 <= buf.count) {
            // 徒步 1Byte
            hiking = buf[index]
            index += 1
        }

        if (index + 1 <= buf.count) {
            // 马拉松 1Byte
            marathon = buf[index]
            index += 1
        }

        if (index + 1 <= buf.count) {
            // 跳绳 1Byte
            skippingRope = buf[index]
            index += 1
        }

        if (index + 1 <= buf.count) {
            // 户外游泳 1Byte
            swim = buf[index]
            index += 1
        }

        if (index + 1 <= buf.count) {
            // 攀岩 1Byte
            rockClimbing = buf[index]
            index += 1
        }

        if (index + 1 <= buf.count) {
            //    滑雪 1Byte
            skiing = buf[index]
            index += 1
        }

        if (index + 1 <= buf.count) {
            // 骑行 1Byte
            ride = buf[index]
            index += 1
        }

        if (index + 1 <= buf.count) {
            // 划船 1Byte
            boat = buf[index]
            index += 1
        }

        if (index + 1 <= buf.count) {
            // 蹦极 1byte
            bungeeJumping = buf[index]
            index += 1
        }

        if (index + 1 <= buf.count) {
            // 登山 1Byte
            mountaineering = buf[index]
            index += 1
        }

        if (index + 1 <= buf.count) {
            // 跳伞 1Byte
            parachuteJump = buf[index]
            index += 1
        }

        if (index + 1 <= buf.count) {
            // 高尔夫 1Byte
            golf = buf[index]
            index += 1
        }

        if (index + 1 <= buf.count) {
            // 冲浪 1Byte
            surfing = buf[index]
            index += 1
        }

        if (index + 1 <= buf.count) {
            // 跑步机 1Byte
            runningMachine = buf[index]
            index += 1
        }

        if (index + 1 <= buf.count) {
            // 主动心率测量开关 1Byte 1：测量打开，0：测量关闭 （默认）
            measureHeartRate = buf[index]
            index += 1
        }

        if (index + 6 <= buf.count) {
            // 蓝牙地址 6Byte
            bleAddress = Array<UInt8>.copyBuffer(buffer: buf, offset: index, length: 6)
            index += 6
        }

        if (index + 1 <= buf.count) {
            // 羽毛球 1Byte
            badminton = buf[index]
            index += 1
        }

        if (index + 1 <= buf.count) {
            // 篮球 1Byte
            basketball = buf[index]
            index += 1
        }

        if (index + 1 <= buf.count) {
            // 足球 1Byte
            footBall = buf[index]
            index += 1
        }

        if (index + 1 <= buf.count) {
            // 血氧 1Byte
            bloodOxygen = buf[index]
            index += 1
        }
    }
    
    @objc func toString() -> String {
        var str = self.yy_modelToJSONString()
        if nil == str {
            str = ""
        }
        
        return str!
    }
}
